#include <bits/stdc++.h>
using namespace std;

void solve(){
    int n;
    string s;
    cin >> n >> s;

    // —— 冲突一：放不下最大值 n ——  
    // p 在 j<n-1 时，前缀 [0..j] 禁止放 n  
    // s 在 i>0   时，后缀 [i..n-1] 禁止放 n  
    // 若 max(j) >= min(i)-1，则 [j+1..i-1] 为空，n 无处可放
    int max_p_for_n = -1;
    int min_s_for_n = n;
    for(int i = 0; i < n; i++){
        if (s[i]=='p' && i < n-1) max_p_for_n = max(max_p_for_n, i);
        if (s[i]=='s' && i >  0  ) min_s_for_n = min(min_s_for_n, i);
    }
    bool conflict_n = (max_p_for_n != -1 && min_s_for_n != n
                       && max_p_for_n >= min_s_for_n - 1);

    // —— 冲突二：放不下最小值 1 ——  
    // p 在 j>=0 时，[0..j] 必须含 1  
    // s 在 i<n-1 时，[i..n-1] 必须含 1  
    // 若 min(j) < max(i)，则两区间无交集，1 无处可放
    int min_p_for_1 = n;
    int max_s_for_1 = -1;
    for(int i = 0; i < n; i++){
        if (s[i]=='p')         min_p_for_1 = min(min_p_for_1, i);
        if (s[i]=='s' && i<n-1) max_s_for_1 = max(max_s_for_1, i);
    }
    bool conflict_1 = (min_p_for_1 != n && max_s_for_1 != -1
                       && min_p_for_1 <  max_s_for_1);

    cout << ((conflict_n || conflict_1) ? "NO\n" : "YES\n");
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--) solve();
    return 0;
}
